<?php
/**
 * XIE--Scorpion
 *
 * 首页搜索
 *
 * time 2016-5-13
 */
namespace App\Http\Controllers\Home;

use Illuminate\Http\Request;
use DB,Input,Redirect,Session,url;
use App\Http\Requests;
use App\Http\Controllers\Controller;

class SearchController extends Controller
{
  
    /*搜索页面*/
    public function search()
    {
        //接受需要搜索的值
        $search_input=isset($_GET['search_input'])?$_GET['search_input']:'';

        //对搜索的词 进行入库记忆
        $hot_search=DB::table('search')->where('sea_name',"$search_input")->first();

        if(empty($hot_search)){
            $hot_data=array('sea_name'=>"$search_input");
            DB::table('search')->insert($hot_data);
        }else{
            $number = $hot_search->number +1;
            $hot_data=array('number'=>"$number");
            DB::table('search')->where('sea_name',"$search_input")->update($hot_data);
        }

        //入库查询搜索的值对应的数据
       	$search=DB::table('post_message')
       	->join('position','post_message.position_id','=','position.position_id')
       	->join('enterprise','post_message.enterprise_id','=','enterprise.enterprise_id')
       	->join('city','post_message.city_id','=','city.city_id')
       	->join('pay','post_message.pay_id','=','pay.pay_id')
       	->join('suffer','post_message.suffer_id','=','suffer.suffer_id')
       	->join('background','post_message.background_id','=','background.background_id')
       	->orwhere("position.position_name",'like',"%$search_input%")
       	->orwhere("enterprise.enterprise_name",'like',"%$search_input%")
       	->get();
        $search2=DB::table('city')->get();
        $pay=DB::table('pay')->get();
        $suffer=DB::table('suffer')->get();
        $background=DB::table('background')->get();

        //热词搜索
        $hot_search = DB::table('search')->orderBy('number', 'desc')->take(8)->get();

       return view('homes/list')->with('search',$search)->with('search_input',$search_input)->with('hot_search',$hot_search)->with('search2',$search2)->with('pay',$pay)->with('suffer',$suffer)->with('background',$background);

    }

    //搜索后工作地点
    public function city_se()
    {
		$city_id=isset($_REQUEST['city_id'])?$_REQUEST['city_id']:'';
		 //var_dump($city_id);die;
		$search2=DB::table('city')->get();

        if($city_id==9){ //全国站
            $we_add=DB::table('post_message')
                ->join('position','post_message.position_id','=','position.position_id')
                ->join('enterprise','post_message.enterprise_id','=','enterprise.enterprise_id')
                ->join('city','post_message.city_id','=','city.city_id')
                ->join('pay','post_message.pay_id','=','pay.pay_id')
                ->join('suffer','post_message.suffer_id','=','suffer.suffer_id')
                ->join('background','post_message.background_id','=','background.background_id')
                ->get();
        }else{  //具体城市划分
            $we_add=DB::table('post_message')
                ->join('position','post_message.position_id','=','position.position_id')
                ->join('enterprise','post_message.enterprise_id','=','enterprise.enterprise_id')
                ->join('city','post_message.city_id','=','city.city_id')
                ->join('pay','post_message.pay_id','=','pay.pay_id')
                ->join('suffer','post_message.suffer_id','=','suffer.suffer_id')
                ->join('background','post_message.background_id','=','background.background_id')
                ->where('post_message.city_id',$city_id)
                ->get();
        }

		return view('homes/city_search')->with('we_add',$we_add)->with('search2',$search2);

    }

    //搜索后的薪资
    public function pay_se()
    {
		$pay_id=isset($_REQUEST['pay_id'])?$_REQUEST['pay_id']:'';
		$search2=DB::table('city')->get();
		$we_add=DB::table('post_message')
		->join('position','post_message.position_id','=','position.position_id')
       	->join('enterprise','post_message.enterprise_id','=','enterprise.enterprise_id')
       	->join('city','post_message.city_id','=','city.city_id')
       	->join('pay','post_message.pay_id','=','pay.pay_id')
       	->join('suffer','post_message.suffer_id','=','suffer.suffer_id')
       	->join('background','post_message.background_id','=','background.background_id')
		->where('post_message.pay_id',$pay_id)
		->get();
		return view('homes/city_search')->with('we_add',$we_add)->with('search2',$search2);
    }

     //搜索后的经验
    public function suffer_se()
    {
		$suffer_id=isset($_REQUEST['suffer_id'])?$_REQUEST['suffer_id']:'';
		 //var_dump($suffer_id);die;
		$search2=DB::table('city')->get();
		$we_add=DB::table('post_message')
		->join('position','post_message.position_id','=','position.position_id')
       	->join('enterprise','post_message.enterprise_id','=','enterprise.enterprise_id')
       	->join('city','post_message.city_id','=','city.city_id')
       	->join('pay','post_message.pay_id','=','pay.pay_id')
       	->join('suffer','post_message.suffer_id','=','suffer.suffer_id')
       	->join('background','post_message.background_id','=','background.background_id')
		->where('post_message.suffer_id',$suffer_id)
		->get();
		return view('homes/city_search')->with('we_add',$we_add)->with('search2',$search2);
    }

     //搜索后的学历
    public function background_se()
    {

		$background_id=isset($_REQUEST['background_id'])?$_REQUEST['background_id']:'';
		 //var_dump($pay_id);die;
		$search2=DB::table('city')->get();
		$we_add=DB::table('post_message')
		->join('position','post_message.position_id','=','position.position_id')
       	->join('enterprise','post_message.enterprise_id','=','enterprise.enterprise_id')
       	->join('city','post_message.city_id','=','city.city_id')
       	->join('pay','post_message.pay_id','=','pay.pay_id')
       	->join('suffer','post_message.suffer_id','=','suffer.suffer_id')
       	->join('background','post_message.background_id','=','background.background_id')
		->where('post_message.background_id',$background_id)
		->get();
		return view('homes/city_search')->with('we_add',$we_add)->with('search2',$search2);
    }

    //职位详情页
    public function jobdetail()
    {
        $message_id=isset($_REQUEST['message_id'])?$_REQUEST['message_id']:'';

        $we_add=DB::table('post_message')
            ->join('position','post_message.position_id','=','position.position_id')
            ->join('enterprise','post_message.enterprise_id','=','enterprise.enterprise_id')
            ->join('city','post_message.city_id','=','city.city_id')
            ->join('pay','post_message.pay_id','=','pay.pay_id')
            ->join('suffer','post_message.suffer_id','=','suffer.suffer_id')
            ->join('background','post_message.background_id','=','background.background_id')
            ->where('post_message.message_id',$message_id)
            ->get();

        return view('homes/jobdetail')->with('we_add',$we_add);

    }



}



?>